package com.dhc.service.controller;

import com.dhc.service.entity.dto.ModifyStudentDto;
import com.dhc.service.entity.dto.StudentFuzzyDto;
import com.dhc.service.entity.vo.StudentVo;
import com.dhc.service.service.StudentService;
import com.dhc.service.utils.result.Result;
import lombok.NonNull;
import org.apache.ibatis.annotations.Param;
import org.apache.logging.log4j.message.ReusableMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Administrator
 * @version 1.0
 * @date 2023/10/08 18:52
 */
@SuppressWarnings({"all"})
@RestController
@RequestMapping("sys/student")
@CrossOrigin
public class StudentController {
	@Autowired
	private StudentService studentService;
	
	/**
	 * 全查询
	 * @return
	 */
	@GetMapping("fullQuery")
	public Result fullQuery() {
		List<StudentVo> list = studentService.fullQuery();
		return Result.ok().data("list", list);
	}

	/**
	 * 模糊查询
	 * @param fuzzyDto
	 * @return
	 */
	@PostMapping("fuzzyQuery")
	public Result fuzzyQuery(@RequestBody @NonNull StudentFuzzyDto fuzzyDto) {
		List<StudentVo> studentList = studentService.fuzzyQuery(fuzzyDto);
		return Result.ok().data("list", studentList);
	}

	/**
	 * 添加數據
	 */
	@PutMapping("addData")
	public Result addData(@RequestBody @NonNull ModifyStudentDto modifyStudentDto) {
		boolean result = studentService.addData(modifyStudentDto);
		return result ? Result.ok().message("数据添加成功") : Result.error().message("数据添加失败");
	}

	/**
	 * 修改数据
	 */
	@PutMapping("updateData")
	public Result updateData(@RequestBody @NonNull ModifyStudentDto modifyStudentDto) {
		boolean result = studentService.updateData(modifyStudentDto);
		return result ? Result.ok().message("数据修改成功") : Result.error().message("数据修改失败");
	}

	/**
	 * 删除单行数据
	 */
	@DeleteMapping("deleteData")
	public Result deleteData(@Param("id") @NonNull String id) {
		boolean result = studentService.deleteData(id);
		return result ? Result.ok().message("数据删除成功") : Result.error().message("数据删除失败");
	}
	
}
